import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'
import Axios from 'axios'
import shoppingCart from './views/shoppingCart.vue'
import Index from './views/Index.vue'
import UserInfo from './views/UserInfo.vue'
import Login from './views/Login'
import OrderList from './views/orderList.vue'
import store from './store/store.js'
import GoodInf from './views/GoodInf.vue'
import Regist from './views/Regist.vue'
import addGood from './views/addGood.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

//安装插件，挂载属性
Vue.use(VueRouter);
Vue.use(ElementUI);
// Vue.use(axios);
Vue.prototype.$axios = Axios;
Vue.config.productionTip = false

let router = new VueRouter({
  
  mode:'history',
  routes:[
    {
      path:'/',
      component:Index
    },
    {
      path:'/shopping',
      component:shoppingCart
    },
    {
      path:'/login',
      component:Login,
      name:'login'
    },
    {
      path:'/center',
      name:'center',
      component:UserInfo,
      children: [
			{
				path: 'orderList',
				component: OrderList
			},
        ]
    },
	{
		name:'good',
		path:'/good',
		component: GoodInf
	},
	{
		name:'regist',
		path:'/regist',
		component: Regist
	},
	{
		name:'addGood',
		path:'/addGood',
		component:addGood
	}
  ]
});

//路由拦截
router.beforeEach((to, from, next)=>{
	var login_key= 'false'
	login_key= window.localStorage.getItem('loginFlag')
	if(to.path === '/login'||to.path === '/'||to.path === '/regist'){
		next();
	}else if(login_key== 'false'){
		alert("请先登录!")
		next('/login');
	}else {
		next();
	}
})

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount('#app')
